class SessionController < ApplicationController
  def new
  end
	def create
	if(params[:email]=="" || params[:password]=="")
		flash[:warning] ="Veuillez remplir tous les champs"
		redirect_to login_url
	else
	  user = User.authenticate(params[:email], params[:password])
	 if user
		session[:user_id] = user.id
		 flash[:notice] = "Vous êtes connecté"
		  target=session[:original_uri] || ''
      session[:original_uri] = nil
      redirect_to target
	  else
		flash[:warning] ="Mot de passe ou email incorrect"
		render "new"
	  end
	end
end

def destroy
  session[:user_id] = nil
  flash[:info] ="Vous êtes déconnecté"
  redirect_to root_url
end
end
